home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles Flirt Up Your Life! (German)
/
Singles Flirt Up Your Life.iso
/
data1.cab
/
Statemachine
/
fridgeSnackChar.lua
< prev
next >
Wrap
Text File
|
2004-01-29
|
11KB
|
370 lines
-- fridge character state machine
beginStateMachine()
onEnter(function(msg)
local fridge = getStateObjectFromID(msg.sender);
storeStateObject("fridge", fridge);
end )
onExit(function(msg)
-- local fridge = retrieveStateObject("fridge");
-- getParent().unlockActionPoints(fridge);
-- removeStateObject("fridge");
end )
-- onReturn(function(msg)
-- -- back from subwalk
-- print("onReturn global");
-- setState(retrieveData("snackCommand"));
-- end )
-- open the fridge
state("open")
onEnter(function(msg)
local fridge = retrieveStateObject("fridge");
if (fridge) then
-- fridge does exist
if (getParent().isOneActionPointLocked(fridge)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(fridge);
end
else
-- fridge does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
-- create the cracker box
-- local crackerBox = fridge.createGameObject("CrackerBox");
-- start to open the fridge
startAnimation("openFridge");
fridge.startAnimation("fridge");
-- show the inside of the fridge
fridge.setChildEnable("fridgeIn", true);
-- show the cracker box
fridge.setChildEnable("CrackerBox", true);
-- send a delayed message for open sound
sendDelayedMsgThis("openSound", 800);
-- send a delayed message for attach
sendDelayedMsgThis("grabCrackerBox", 5000);
-- send a delayed message for close sound
sendDelayedMsgThis("closeSound", 6000);
end )
onMsg("openSound", function(msg)
local fridge = retrieveStateObject("fridge");
fridge.playSound("fridgeOpen");
fridge.stopSound("fridgeLoop");
end)
onMsg("grabCrackerBox", function(msg)
-- attach cracker box to left hand of character
local crackerBox = getParent().loadGameObject("StandardGO", "crackerBox");
storeStateObject("crackerBox", crackerBox);
getParent().attachLeftObjectHolder(crackerBox);
local fridge = retrieveStateObject("fridge");
fridge.playSound("fridgeTake");
fridge.setChildEnable("CrackerBox", false);
end)
onMsg("closeSound", function(msg)
local fridge = retrieveStateObject("fridge");
fridge.playSound("fridgeClose");
fridge.stopSound("fridgeLoop");
end)
onMsg("canceled", function(msg)
local crackerBox = getParent().getLeftHeldObject();
if (crackerBox) then
getParent().detachLeftObjectHolder();
crackerBox.deleteGameObject();
-- hide the cracker box
--fridge.setChildEnable("CrackerBox", false);
end
exitStateMachine();
end)
onMsg("end", function(msg)
-- hide the inside of the fridge
local fridge = retrieveStateObject("fridge");
fridge.setChildEnable("fridgeIn", false);
if testCancel() then
sendMsgThis("canceled");
-- -- detach cracker box if attached to left hand
-- local crackerBox = getParent().getLeftHeldObject();
-- if (crackerBox) then
-- getParent().detachLeftObjectHolder();
-- crackerBox.deleteGameObject();
-- -- hide the cracker box
-- --fridge.setChildEnable("CrackerBox", false);
-- end
-- exitStateMachine();
else
--setState(retrieveData("snackCommand"));
local actionPoint = getParent().findPointNear(1.0, 5.0);
if (actionPoint) then
if (walkToPointImmediate(actionPoint)) then
local wsoContext = StateMachineContext();
--wsoContext.storeStateObject("fridge", fridge);
--queueStateMachine("fridgeSnackChar." .. retrieveData("snackCommand"), fridge, wsoContext);
enterStateMachine("subwalk.walk");
else
print("no path found");
sendMsgThis("canceled");
end
-- if (walkToActionPoint(actionPoint)) then
-- local wsoContext = StateMachineContext();
-- --wsoContext.storeStateObject("fridge", fridge);
-- queueStateMachine("fridgeSnackChar." .. retrieveData("snackCommand"), fridge, wsoContext);
-- exitStateMachine();
-- else
-- print("no path found");
-- sendMsgThis("canceled");
-- end
else
print("no near free space found");
setState(retrieveData("snackCommand"));
end
end
end )
onReturn(function(msg)
-- back from subwalk
print("onReturn open");
setState(retrieveData("snackCommand"));
end )
onExit(function(msg)
print("open exit");
local fridge = retrieveStateObject("fridge");
getParent().unlockActionPoints(fridge);
removeStateObject("fridge");
end )
-- eat a snack
state("eatSnack")
onEnter(function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
exitStateMachine();
else
local crackerBox = getParent().getLeftHeldObject();
local eatSnack = getParent().startActivity("eatSnack", crackerBox);
local length = getActivityLength(eatSnack);
--flipPoseDirection(); -- animation ist wrong oriented
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
sendMsgThis("startLoop");
crackerBox.buy(); -- pay money for food
end
end )
onExit(function(msg)
local crackerBox = getParent().getLeftHeldObject();
if (crackerBox) then
print("deleting crackerBox")
getParent().stopAllActivities(crackerBox);
getParent().detachLeftObjectHolder();
crackerBox.deleteGameObject();
end
createTrash(0.1);
--flipPoseDirection(); -- animation ist wrong oriented
end )
onMsg("startLoop", function(msg)
startAnimation("eatSnackLoop");
sendDelayedMsgThis("eatSound", 2200);
sendDelayedMsgThis("eatSound", 4500);
end )
onMsg("eatSound", function(msg)
getParent().playSound("eat1");
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
exitStateMachine();
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("complete", function(msg)
exitStateMachine()
end )
onMsg("end", function(msg)
if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
exitStateMachine();
else
sendMsgThis("startLoop");
end
end )
state("eatVegSnack")
onEnter(function(msg)
local crackerBox = getParent().getLeftHeldObject();
local eatSnack = getParent().startActivity("eatSnack", crackerBox);
local length = getActivityLength(eatSnack);
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
sendMsgThis("startLoop");
this.actionComplete();
end )
onExit(function(msg)
local crackerBox = getParent().getLeftHeldObject();
getParent().stopAllActivities(crackerBox);
if (crackerBox) then
getParent().detachLeftObjectHolder();
crackerBox.deleteGameObject();
end
end )
onMsg("startLoop", function(msg)
startAnimation("eatSnackLoop");
sendDelayedMsgThis("eatSound", 2200);
sendDelayedMsgThis("eatSound", 4500);
end )
onMsg("eatSound", function(msg)
getParent().playSound("eat1");
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
exitStateMachine();
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
exitStateMachine();
else
sendMsgThis("startLoop");
end
end )
-- -- eat a vegetarian snack
-- state("eatVegSnack")
--
-- onEnter(function(msg)
-- startAnimation("eatSnackLoop");
-- local crackerBox = getParent().getLeftHeldObject();
-- getParent().startActivity("eat", crackerBox);
--
-- sendDelayedMsgThis("boxEmpty", 30000);
-- this.actionComplete();
-- end )
--
-- onExit(function(msg)
-- local crackerBox = getParent().getLeftHeldObject();
-- getParent().stopAllActivities(crackerBox);
-- if (crackerBox) then
-- getParent().detachLeftObjectHolder();
-- crackerBox.deleteGameObject();
-- end
-- end )
--
--
-- onMsg("boxEmpty", function(msg)
-- -- remove the cracker box
-- print("boxEmpty");
-- exitStateMachine();
-- end )
--
-- onMsg("end", function(msg)
-- if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
-- exitStateMachine();
-- else
-- startAnimation("eatSnackLoop");
-- doSomething();
-- end
-- end )
--
-- -- eat a snack
-- state("eatVegSnack")
--
-- onEnter(function(msg)
-- startAnimation("eatSnackLoop");
-- local fridge = retrieveStateObject("fridge");
-- getParent().startActivity("eatVegSnack", fridge)
-- sendDelayedMsgThis("boxEmpty", 30000);
-- end )
--
-- onExit(function(msg)
-- local fridge = retrieveStateObject("fridge");
-- if (fridge) then getParent().stopAllActivities(fridge) end;
-- end )
--
--
-- onMsg("boxEmpty", function(msg)
-- -- remove the cracker box
-- print("boxEmpty");
-- local crackerBox = getParent().getLeftHeldObject();
-- if (crackerBox) then
-- getParent().detachLeftObjectHolder();
-- crackerBox.deleteGameObject();
-- -- hide the cracker box
-- --local fridge = retrieveStateObject("fridge");
-- --fridge.setChildEnable("CrackerBox", false);
-- end
-- exitStateMachine();
-- end )
--
--
-- onMsg("end", function(msg)
-- if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
-- -- remove the cracker box
-- local crackerBox = getParent().getLeftHeldObject();
-- if (crackerBox) then
-- getParent().detachLeftObjectHolder();
-- crackerBox.deleteGameObject();
-- -- hide the cracker box
-- --local fridge = retrieveStateObject("fridge");
-- --fridge.setChildEnable("CrackerBox", false);
-- end
-- exitStateMachine();
-- else
-- startAnimation("eatSnackLoop");
-- doSomething();
-- end
-- end )
--
endStateMachine()